import { createRouter, createWebHistory } from 'vue-router';
import { staticRouter, errorRouter } from "@/router/modules/staticRouter";
import { data } from "../router/data";
import { getFlatMenuList } from "@/utils/index";
// 引入 views 文件夹下所有 vue 文件
const modules = import.meta.glob("@/views/**/*.vue");
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [...staticRouter, ...errorRouter]
})
console.log('router')
let list = [];
list = getFlatMenuList(data)
// 3.添加动态路由
list.forEach(item => {
  // item.children && delete item.children;
  if (item.component && typeof item.component == "string") {
    item.component = modules["/src/views" + item.component + ".vue"];
  }
  if (item.meta.isFull) {
    router.addRoute(item);
  } else {
    router.addRoute("layout", item);
  }
});
export default router
